package com.meichis.mcsappframework.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

public class MCChlidListView extends ListView {
	private boolean canClick = false; //默认不可以点击item
	public MCChlidListView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MCChlidListView(Context context) {
		super(context);
	}

	public MCChlidListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}
	//设置item是否可以被点击
	public void setCanClick(boolean canClick) {
		this.canClick = canClick;
	}
	// 将 onInterceptTouchEvent的返回值设置为false，取消其对触摸事件的处理，将事件分发给子view

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if (canClick) {
			return super.onInterceptTouchEvent(ev);
		}else {
			return false;
		}
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		if (canClick) {
			return super.onTouchEvent(ev);
		}else {
			return false;
		}
	}

	@Override
	public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// 根据模式计算每个child的高度和宽度
		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
				MeasureSpec.AT_MOST);
		super.onMeasure(widthMeasureSpec, expandSpec);
	}

}
